String src = 'apps.html'
String dist = 'apps-local.html'

def f = new File(src)

def ll = f.readLines()
def ll2 = []
//def pat = /background\-image: url\(([^\)]+)\)/
def pat = /img src="(http[^"]+)"/
def rand = new Random()

for(one in ll){
	def mat = one =~ pat

	if(mat){
		String urlRemote = mat[0][1]
		String urlLocal = 'img/' + System.currentTimeMillis() + '-' + rand.nextInt(10000) + '.jpg'

		new FileOutputStream(new File(urlLocal)) << new URL(urlRemote).openStream()
		ll2 << one.replace(urlRemote, '/store/' + urlLocal)
	}else{
		ll2 << one
	}
}

new File(dist).withPrintWriter('utf-8'){w ->
	for(one in ll2){
		w.println one
	}
}